import { createStore } from 'vuex'
import {allTopices, addTopices ,  delTopices,updateTopices} from "../API"

 // 创建一个新的 store 实例
const store = createStore({
    state() {
        return {
            drawerBol: false,
            inventoryDates: '全部',
            tableDate:[]
        }
    },
    mutations: {
        DRAWERBOL(state, bol) {
            state.drawerBol = bol
        },
        INVENTORYDATE(state, bol) {
            console.log(bol);
            state.inventoryDates = bol
        },
        // 获取所有话题数据
        ALLTOPICES(state,data){
            state.tableDate=data
        }
    },
    actions: {

        // 查询所有
      async allList(store) {
           let data =  await allTopices()
           store.commit("ALLTOPICES",data.data)
           console.log(data);
           return data.data
        },
        // 添加
       async add(store,conten) {
             await addTopices(conten)
            let data =  await allTopices()
            store.commit("ALLTOPICES",data.data)
        },
        // 更改
        async updateToplc(store,conten){
          let datas=  await updateTopices(conten)
          console.log(datas);
            let data =  await allTopices()
            store.commit("ALLTOPICES",data.data)
        },
        // 删除
        async delTopic(store,conten){
            let datas=  await delTopices(conten)
            console.log(datas);
              let data =  await allTopices()
              store.commit("ALLTOPICES",data.data)
          }
    }
})

export default store